package com.cater.sys.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.cater.common.BaseEntity;
import com.cater.common.PageResult;
import com.cater.query.CommonQuery;
import com.cater.sys.dao.TypeDao;
import com.cater.sys.entity.Type;
import com.cater.sys.service.BaseService;

/**
 * @author 作者: yy
 * @date 创建时间：2017年1月11日 上午9:54:58
 * @version 1.0
 */
@Service
public class TypeServiceImpl implements BaseService<Type, CommonQuery, Integer> {
	@Autowired
	private TypeDao dao;

	@Override
	public PageResult<Type> findPageResult(CommonQuery query) {
		PageResult<Type> result = new PageResult<Type>();
		result.setPage(query.getPage());
		result.setPageSize(query.getRows());
		int count = dao.findCount(query);
		int first = (query.getPage() - 1) * query.getRows();
		int max = query.getRows();
		List<Type> list = dao.findList(query, first, max);
		result.setRows(list);
		result.setRecords(count);
		return result;
	}

	@Override
	public List<Type> getAll() {
		return dao.getAll();
	}

	@Override
	public List<Type> getAllCommon(CommonQuery query) {
		return dao.getAllCommon(query);
	}

	@Override
	public int save(Type t) {
		BaseEntity.getCreate(t);
		return dao.save(t);
	}

	@Override
	public void update(Type t) {
		BaseEntity.getupdate(t);
		dao.update(t);
	}

	@Override
	public void delete(String id) {
		dao.delete(Integer.valueOf(id));
	}

	@Override
	public Type getById(String id) {
		return dao.getById(Integer.valueOf(id));
	}

	public List<Type> getTypeBypid(Integer id) {
		return dao.getTypeBypid(id);
	}

	public List<Type> getParent() {
		return dao.getParent();
	}

	public List<Type> getChild(Integer pid) {
		return dao.getChild(pid);
	}

	public List<Type> getName(Integer pid) {
		return dao.getName(pid);
	}

	@Override
	public String saves(Type t) {
		// TODO Auto-generated method stub
		return null;
	}

}
